package com.uenpay.im.serializations;

import com.qyx.android.entity.GroupTalkEntity;
import com.uenpay.im.IMApplication;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

/**
 * 序列化群列表信息
 *
 * @author SL
 *
 */
public class GroupListSerializer {
	public static GroupTalkEntity deserializeUser(JSONObject json) {
		GroupTalkEntity groups = new GroupTalkEntity();
		groups.has_count = json.optInt("custnum");
		groups.group_name = json.optString("chatname");
		groups.group_id = json.optLong("chatid");
		if (IMApplication.getCustId().equals(json.optInt("custid") + "")) {
			groups.is_admin = 1;
		} else {
			groups.is_admin = 0;
		}
		groups.max_count = json.optInt("maxcustnum");
		return groups;
	}

	public static ArrayList<GroupTalkEntity> deserializeGroups(JSONArray jsons) {
		ArrayList<GroupTalkEntity> arrayList = new ArrayList<GroupTalkEntity>();
		for (int i = 0; i < jsons.length(); i++) {
			arrayList.add(deserializeUser(jsons.optJSONObject(i)));
		}
		return arrayList;
	}
}
